package chapter2;

import util.PrintUtils;

/**
 * insert sort 插入排序
 */
public class InsertSort1 {

    public void sort(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int currEle = array[i];
            int j = i - 1;
            while (j >= 0 && array[j] > currEle) {
                array[j+1] = array[j];
                j --;
            }
            array[j+1] = currEle;
        }
    }

    public static void main(String[] args) {
        int[] arr = {31, 41, 59, 26, 41, 58};
        new InsertSort1().sort(arr);
        PrintUtils.PrintArray(arr);
    }
}